<?php
session_start();
date_default_timezone_set("America/Sao_Paulo");
setlocale(LC_ALL, 'pt_BR');
include "../../biblioteca/funcao.php";
?>
<html>
    
    <head>
        
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" href="../../plugin/estilo.css">
        <link rel="stylesheet" type="text/css" href="../../plugin/bootstrap/css/bootstrap-responsive.css">
        <link rel="stylesheet" type="text/css" href="../../plugin/bootstrap/css/bootstrap.css"> 
        <script type="text/javascript" src="../../plugin/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="../../plugin/bootstrap/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="../../plugin/funcao.js" ></script>

        <title><?= $t_impri ?></title>
        <link href="../../base/favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
            <!--[if lt IE 9]>
            <script src="plugin/html5.js"></script>
        <![endif]-->
        
    </head>
    
    <body onLoad="window.print();">
        
        <div style="padding:20px;">
        
            <?php

            $sql = "SELECT chamado.cha_id,
            chamado.cha_nome,
            chamado.cha_msg,
            chamado.cha_data,
            chamado.cha_hora,
            setor.set_nome,
            setor.set_id,
            cliente.cli_code,
            cliente.cli_id,
            cliente.cli_nome,
            cliente.cli_guerra,
            cliente.cli_tel,
            cliente.cli_email,
            posto.pos_nome 
            FROM chamado 
            INNER JOIN setor ON setor.set_id=chamado.set_id 
            INNER JOIN cliente ON cliente.cli_id=chamado.cli_id 
            LEFT JOIN posto ON posto.pos_id=cliente.pos_id 
            WHERE chamado.status='1' AND chamado.cha_id='{$_GET['cha_id']}'
            ORDER BY chamado.cha_id DESC";
            $res = sql($sql);
            $linha = mysql_fetch_array($res);

            if ($linha['cli_guerra'] != "") { $nome = $linha['cli_guerra']; } else { $nome = $linha['cli_nome']; }

            $sql_acao = "SELECT cha_status.cha_sta_id,
            cha_status.cha_sta_nome,
            cha_status.cha_sta_cor,
            acao.aca_msg,
            acao.aca_data,
            acao.aca_hora
            FROM acao 
            INNER JOIN cha_status ON cha_status.cha_sta_id=acao.cha_sta_id 
            WHERE acao.cha_id='{$linha['cha_id']}' 
            ORDER BY acao.aca_id DESC";
            $res_acao = sql($sql_acao);
            $linha_acao = mysql_fetch_array($res_acao);
            $cha_sta_id = $linha_acao['cha_sta_id'];
            $aca_msg = $linha_acao['aca_msg'];
            $cha_id = $linha['cha_id'];
            $set_id = $linha['set_id'];
            $status = "<span class='color:{$linha_acao['cha_sta_cor']};font-weight:bold;'>{$linha_acao['cha_sta_nome']}</span>";

            echo "<h4><i class='icon-bookmark'></i> {$t_detalhe_chamado} - N&deg; <strong>{$linha['cha_id']}</strong></h4><p style='text-align:right;'><a href='#' onclick='window.print();' style='font-size:13px;'><i class='icon-print'></i> {$t_impri}</a></p>";
            echo "<h5><i class='icon-user'></i> {$t_dadoscada}</h5>";
            echo "{$t_usuario}: {$linha['cli_code']}&nbsp;&nbsp;-&nbsp;&nbsp;{$linha['pos_nome']}&nbsp;&nbsp;$nome&nbsp;&nbsp;-&nbsp;&nbsp;{$linha['cli_tel']}&nbsp;{$linha['cli_email']}&nbsp;{$linha['cli_sala']}<br><br>";
            echo "<h5><i class='icon-book'></i> {$t_chamados}</h5>";
            echo "{$t_titulo}: {$linha['cha_nome']}<br>";
            echo "{$t_desc}: ".nl2br($linha['cha_msg'])."<br>";
            echo "{$t_setor}: {$linha['set_nome']}<br>";
            echo "{$t_status}: $status<br>";
            echo "{$t_data}/{$t_hora}: ".toDataBr($linha['cha_data'])."&nbsp;&nbsp;-&nbsp;&nbsp;{$linha['cha_hora']} Z<br><br>";
            echo "<h5><i class='icon-list-alt'></i> A&ccedil;&otilde;es</h5>";
            $sql_acao = "SELECT * FROM acao WHERE status='1' AND cha_id='{$linha['cha_id']}' ORDER BY aca_id DESC";
            $res_acao = sql($sql_acao);
            while($linha_acao = mysql_fetch_array($res_acao)) {
            ?>
                <p>. 
                <?="{$linha_acao['aca_msg']}<br>&nbsp;&nbsp;-&nbsp;&nbsp;".todatabr($linha_acao['aca_data'])."&nbsp;&nbsp;{$linha_acao['aca_hora']} h";
                ?>
                </p>
            <?php 
            } 
            ?>
                
        </div>
        
    </body>
    
</html>